package com.link.base.base.autoconfig.autoconfig.service;

import com.link.base.base.autoconfig.StringTool;
import com.link.base.base.autoconfig.autoconfig.dao.mybatis.mapper.LnkInnerFieldMapper;
import com.link.base.base.autoconfig.autoconfig.dao.mybatis.mapper.LnkInnerLinkMapper;
import com.link.base.base.autoconfig.autoconfig.dao.mybatis.mapper.LnkInnerObjectMapper;
import com.link.base.base.autoconfig.autoconfig.dao.mybatis.mapper.LnkInnerWhereMapper;
import com.link.base.base.autoconfig.autoconfig.model.*;
import com.link.base.user.model.CoreUser;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.basic.service.ServiceException;
import com.link.core.modules.BatchExportFileWriter;
import com.link.core.util.DateUtil;
import com.link.core.util.StringUtils;
import com.link.core.util.UserUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service("lnkInnerObjectService")
public class LnkInnerObjectServiceImpl extends BasicServiceImpl<LnkInnerObject> implements LnkInnerObjectService {
    @Resource
    private LnkInnerObjectMapper lnkInnerObjectMapper;
    @Resource
    private LnkInnerFieldMapper lnkInnerFieldMapper;
    @Resource
    private LnkInnerLinkMapper lnkInnerLinkMapper;
    @Resource
    private LnkInnerWhereMapper lnkInnerWhereMapper;
    @Resource
    private KeyGenerateService keyGenerateService;
    private static final Logger logger = LogManager.getLogger(LnkInnerObjectServiceImpl.class);

    /**
     * 随机数
     */
    private static Random RANDOM = new Random();

    @Override
    public BasicMapper<LnkInnerObject> getBasicMapper() {
        return lnkInnerObjectMapper;
    }

    @Override
    public String newQueryTable(LnkInnerObject record) throws Exception {
        Map<String, String> systemField = new HashMap<String, String>();
        systemField.put("id", "");
        systemField.put("created", "");
        systemField.put("created_by", "");
        systemField.put("last_upd", "");
        systemField.put("last_upd_by", "");
        systemField.put("orgId", "");
        systemField.put("postnId", "");
        String OutMsg = "";
        List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(record);
        for (LnkInnerObject header : headers) {
            Map<String, String> lineField = new HashMap<String, String>();
            OutMsg += "SELECT " + System.getProperty("line.separator");
            OutMsg += "     " + FormatStringToLength("T1.ROW_ID") + " as " + FormatStringToLength("id") + "/*记录ID*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.CREATED") + " as "
                    + FormatStringToLength("created") + "/*创建时间*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.CREATED_BY") + " as " + FormatStringToLength("createdBy")
                    + "/*创建者ID*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.LAST_UPD") + " as "
                    + FormatStringToLength("lastUpdated") + "/*最后更新时间*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.LAST_UPD_BY") + " as " + FormatStringToLength("lastUpdatedBy")
                    + "/*最后更新者ID*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.ORG_ID") + " as " + FormatStringToLength("orgId") + "/*组织ID*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("T1.POSTN_ID") + " as " + FormatStringToLength("postnId")
                    + "/*职位ID*/" + System.getProperty("line.separator");

            LnkInnerLink linkExample = new LnkInnerLink();
            linkExample.setParentid(record.getId());
            //linkExample.setAttr02("Y");没用，sql没加上

            LnkInnerField fieldExample = new LnkInnerField();
            fieldExample.setParentid(record.getId());
            //fieldExample.setAttr02("Y");

            LnkInnerWhere whereExample = new LnkInnerWhere();
            whereExample.setParentid(record.getId());

            String LinkString = "    FROM     " + FormatStringToLength(header.getBasetable()) + " "
                    + header.getBasetablealais() + System.getProperty("line.separator");
            String whereString = "        WHERE 1=1" + System.getProperty("line.separator");
            List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(linkExample);// query link
            List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(fieldExample);// query Field
            List<LnkInnerWhere> wheres = lnkInnerWhereMapper.queryByInner(whereExample);
            /* 处理基表的字段 */
            for (LnkInnerField field : fields) {
                if (!"Y".equals(field.getActiveflag()) || !"Y".equals(field.getAttr02())) {
                    continue;
                }
                if (!StringUtils.isNull(field.getJoinname())) {
                    continue;
                }
                if (systemField.containsKey(field.getName())) {
                    continue;
                }
                if (lineField.containsKey(field.getName())) {
                    continue;
                }
                OutMsg += "    ," + FormatStringToLength("T1." + field.getColumnname()) + " as "
                        + FormatStringToLength(field.getName()) + "/*" + field.getDisplayname() + "*/"
                        + System.getProperty("line.separator");
                lineField.put(field.getName(), "");
            }
            for (LnkInnerLink link : links) {
                String linkname = link.getName();
                if (!"Y".equals(link.getAttr02())) {
                    continue;
                }
                LinkString += "        ," + FormatStringToLength(link.getTablename()) + " " + link.getAttr01()
                        + System.getProperty("line.separator");
                whereString += "        AND (" + link.getLinkcoms() + ")" + System.getProperty("line.separator");
                for (LnkInnerField field : fields) {
                    String fieldlinname = field.getJoinname();
                    if (!"Y".equals(field.getActiveflag())) {
                        continue;
                    }
                    if (!StringUtils.equals(linkname, fieldlinname) || StringUtils.isNull(fieldlinname)) {
                        continue;
                    }
                    if (systemField.containsKey(field.getName())) {
                        continue;
                    }
                    if (lineField.containsKey(field.getName())) {
                        continue;
                    }
                    OutMsg += "    ," + FormatStringToLength(link.getAttr01() + "." + field.getColumnname()) + " as "
                            + FormatStringToLength(field.getName()) + "/*" + field.getDisplayname() + "*/"
                            + System.getProperty("line.separator");
                    lineField.put(field.getName(), "");
                }
            }

            for (LnkInnerWhere where : wheres) {
                String whereComs = where.getLinkcoms();
                if (!StringUtils.isBlank(whereComs) && "Y".equals(where.getAttr02())) {
                    if (whereComs.trim().startsWith("<") || whereComs.trim().toUpperCase().startsWith("AND ")) {
                        whereString += "        " + where.getLinkcoms() + "" + System.getProperty("line.separator");
                    } else {
                        whereString += "        AND " + where.getLinkcoms() + "" + System.getProperty("line.separator");
                    }
                }

            }
            OutMsg += LinkString + System.getProperty("line.separator") + whereString
                    + System.getProperty("line.separator");
        }
        return OutMsg;
    }

    /**
     * 生成oracle建表语句
     */
    @Override
    public String newTable(LnkInnerObject record) throws Exception {
        Map<String, String> systemField = new HashMap<String, String>();
        systemField.put("ROW_ID", "");
        systemField.put("CREATED", "");
        systemField.put("CREATED_BY", "");
        systemField.put("LAST_UPD", "");
        systemField.put("LAST_UPD_BY", "");
        systemField.put("CORP_ID", "");
        systemField.put("ORG_ID", "");
        systemField.put("POSTN_ID", "");
        String OutMsg = "";
        LnkInnerObject qps = new LnkInnerObject();
        qps.setId(record.getId());
        qps.setAttr02("Y");
        List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(qps);
        for (LnkInnerObject header : headers) {
            Map<String, String> lineField = new HashMap<String, String>();
            OutMsg += "--DROP TABLE " + header.getBasetable() + ";" + System.getProperty("line.separator");
            OutMsg += "CREATE TABLE " + header.getBasetable() + " (" + System.getProperty("line.separator");
            OutMsg += "     " + FormatStringToLength("ROW_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0) NOT NULL") + "/*记录ID*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("CREATED") + " "
                    + FormatStringToLength30("DATE DEFAULT SYSDATE NOT NULL") + "/*创建时间*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("CREATED_BY") + " "
                    + FormatStringToLength30("NUMBER(30,0) NOT NULL") + "/*创建者*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("LAST_UPD") + " "
                    + FormatStringToLength30("DATE DEFAULT SYSDATE NOT NULL") + "/*最后更新时间*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("LAST_UPD_BY") + " "
                    + FormatStringToLength30("NUMBER(30,0) NOT NULL") + "/*最后更新者*/"
                    + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("CORP_ID") + " " + FormatStringToLength30("NUMBER(30,0)")
                    + "/*公司账套ID*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("ORG_ID") + " " + FormatStringToLength30("NUMBER(30,0)")
                    + "/*组织ID*/" + System.getProperty("line.separator");
            OutMsg += "    ," + FormatStringToLength("POSTN_ID") + " " + FormatStringToLength30("NUMBER(30,0)")
                    + "/*职位ID*/" + System.getProperty("line.separator");
            String commentString = "";
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".ROW_ID is '记录的主键';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".CREATED is '创建时间';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".CREATED_BY is '创建者';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".LAST_UPD is '最后更新时间';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".LAST_UPD_BY is '最后更新者';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".CORP_ID is '公司账套ID';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".ORG_ID is '组织ID';"
                    + System.getProperty("line.separator");
            commentString += "COMMENT ON COLUMN " + header.getBasetable() + ".POSTN_ID is '职位ID';"
                    + System.getProperty("line.separator");
            String IndexString = "CREATE UNIQUE INDEX " + header.getBasetable() + "_PK ON " + header.getBasetable()
                    + " (ROW_ID);" + System.getProperty("line.separator");
            int indexcountU = 1;
            int indexcountN = 1;
            String AddcolString = "/* 以下脚本为在现有表中增加字段的脚本，请在plsql developer的命令行中执行*/"
                    + System.getProperty("line.separator") + "/*" + System.getProperty("line.separator");
            AddcolString += "ALTER TABLE " + header.getBasetable() + " add " + FormatStringToLength("CORP_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*公司账套ID*/" + System.getProperty("line.separator");
            AddcolString += "ALTER TABLE " + header.getBasetable() + " add " + FormatStringToLength("ORG_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*组织ID*/" + System.getProperty("line.separator");
            AddcolString += "ALTER TABLE " + header.getBasetable() + " add " + FormatStringToLength("POSTN_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*职位ID*/" + System.getProperty("line.separator");
            String ModifyString = "/* 以下脚本为在现有表中修改字段的脚本，请在plsql developer的命令行中执行*/"
                    + System.getProperty("line.separator") + "/*" + System.getProperty("line.separator");
            ModifyString += "ALTER TABLE " + header.getBasetable() + " modify " + FormatStringToLength("CORP_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*公司账套ID*/" + System.getProperty("line.separator");
            ModifyString += "ALTER TABLE " + header.getBasetable() + " modify " + FormatStringToLength("ORG_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*组织ID*/" + System.getProperty("line.separator");
            ModifyString += "ALTER TABLE " + header.getBasetable() + " modify " + FormatStringToLength("POSTN_ID") + " "
                    + FormatStringToLength30("NUMBER(30,0);") + "/*职位ID*/" + System.getProperty("line.separator");
            LnkInnerField qps1 = new LnkInnerField();
            qps1.setParentid(record.getId());
            List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(qps1);
            String lastCreatedString = header.getCreated(10).substring(0, 10);
            String lastCreatedByName = header.getCreatedByName();
            for (LnkInnerField field : fields) {
                //循环字段列表
                String name = field.getName();
                String createdByInfo = "";
                String createdString = field.getCreated(10).substring(0, 10);
                if (!StringUtils.equals(lastCreatedString, createdString)) {
                    lastCreatedString = createdString;
                    createdByInfo = System.getProperty("line.separator") + "    /*created:" + createdString
                            + ",createdBy:" + field.getCreatedByName() + "*/" + System.getProperty("line.separator");
                }
                if (!StringUtils.equals(lastCreatedByName, field.getCreatedByName())) {
                    lastCreatedByName = field.getCreatedByName();
                    createdByInfo = System.getProperty("line.separator") + "    /*created:" + createdString
                            + ",createdBy:" + field.getCreatedByName()
                            + "*/" + System.getProperty("line.separator");
                }

                if (!"Y".equals(field.getActiveflag())) {
                    logger.info("field.getActiveflag() is:");
                    logger.info(field.getActiveflag());
                    continue;
                }
                if ("Y".equals(field.getCalc())) {
                    logger.info("field.getCalc() is:");
                    logger.info(field.getActiveflag());
                    continue;
                }
                if (!StringUtils.isNull(field.getJoinname())) {
                    logger.info("field.getJoinname() is:");
                    logger.info(field.getJoinname());
                    continue;
                }
                if (StringUtils.isNull(field.getColumnname())) {
                    logger.info("getColumnname field is blank!");
                    logger.info(field.getDisplayname());
                    continue;
                }
                if (systemField.containsKey(field.getColumnname())) {
                    logger.info("getColumnname is system field:");
                    logger.info(field.getColumnname());
                    continue;
                }
                if (lineField.containsKey(field.getColumnname())) {
                    logger.info("getColumnname field is aleady exists!");
                    logger.info(field.getColumnname());
                    continue;
                }

                String FieldType = "";
                if ("VARCHAR2".equals(field.getColumntype())) {
                    FieldType = "VARCHAR2(" + field.getColumnlength() + " CHAR)";
                } else if ("NUMBER".equals(field.getColumntype())) {
                    FieldType = "NUMBER(22,7)";
                } else if ("DATE".equals(field.getColumntype())) {
                    FieldType = "DATE";
                } else if ("CLOB".equals(field.getColumntype())) {
                    FieldType = "CLOB";
                } else if ("CHAR".equals(field.getColumntype())) {
                    FieldType = "CHAR(" + field.getColumnlength() + ")";
                } else if ("BIGINT".equals(field.getColumntype())) {
                    logger.error("ORACLE中无【BIGINT】类型字段，请修改字段配置");
                    throw new BasicServiceException("ORACLE中无【BIGINT】类型字段，请修改字段配置");
                }

                OutMsg += "    ," + FormatStringToLength(field.getColumnname()) + " "
                        + FormatStringToLength30(FieldType) + "/*" + field.getDisplayname()
                        + "*/" + System.getProperty("line.separator");
                commentString += "COMMENT ON COLUMN " + header.getBasetable() + "." + field.getColumnname() + " is '"
                        + field.getDisplayname() + "';" + System.getProperty("line.separator");
                lineField.put(field.getColumnname(), "");
                if ("Normal".equals(field.getIndextype())) {
                    IndexString += "CREATE INDEX " + header.getBasetable() + "_N" + indexcountN + " ON "
                            + header.getBasetable() + " (" + field.getColumnname() + ");"
                            + System.getProperty("line.separator");
                    indexcountN++;
                } else if ("Unique".equals(field.getIndextype())) {
                    IndexString += "CREATE UNIQUE INDEX " + header.getBasetable() + "_U" + indexcountU + " ON "
                            + header.getBasetable() + " (" + field.getColumnname() + ");"
                            + System.getProperty("line.separator");
                    indexcountU++;
                }
                if (!"".equals(createdByInfo)) {
                    AddcolString += createdByInfo;
                    ModifyString += createdByInfo;
                }
                AddcolString += "ALTER TABLE " + header.getBasetable() + " add "
                        + FormatStringToLength(field.getColumnname()) + " " + FormatStringToLength30(FieldType + ";")
                        + "/*" + field.getDisplayname() + "*/" + System.getProperty("line.separator");
                ModifyString += "ALTER TABLE " + header.getBasetable() + " modify "
                        + FormatStringToLength(field.getColumnname()) + " " + FormatStringToLength30(FieldType + ";")
                        + "/*" + field.getDisplayname() + "*/" + System.getProperty("line.separator");
            }
            OutMsg += ");" + System.getProperty("line.separator") + "COMMENT ON TABLE " + header.getBasetable() + " IS '"
                    + header.getAttr01() + "';" + System.getProperty("line.separator");
            OutMsg += commentString + System.getProperty("line.separator") + System.getProperty("line.separator");
            OutMsg += IndexString + System.getProperty("line.separator") + System.getProperty("line.separator")
                    + AddcolString + "*/" + System.getProperty("line.separator");
            OutMsg += ModifyString + "*/" + System.getProperty("line.separator");
        }
        return OutMsg;
    }

    /**
     * <p>获取service接口文件内容并替换关键字符串</p>
     *
     * @author yrf
     * @param Namespace
     * @param objName
     * @param FolderName
     * @param comments
     * @return
     */
    private String GetServiceString(String Namespace, String objName, String FolderName, String comments) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("service");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        OutString = OutString.replace("&comments&", comments);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy/MM/dd HH:mm"));
        return OutString;
    }

    private String GetPublicTemplateString(String Namespace, String objName, String FolderName, String filename) {
        /*createdBy: 黄安邦
         *Created:2018-05-20
         * comments:根据文件名获取内容,并进行一些基本的替换动作
         * @filename:文件名,相对路径,例如/app /crm
         * */
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent(filename);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = PublicReplace(OutString, Namespace, objName, FolderName);
        OutString = OutString.replace("&package&", Namespace);
        String thisLobjName = LobjName;
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", thisLobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;
    }

    /**
     * <p>获取service实现类文件内容并替换关键字符串</p>
     *
     * @author yrf
     * @param Namespace
     * @param objName
     * @param FolderName
     * @param comments
     * @return
     */
    private String GetServiceImplString(String Namespace, String objName, String FolderName, String comments) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("serviceimpl");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        OutString = OutString.replace("&comments&", comments);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy/MM/dd HH:mm"));
        return OutString;
    }

    /**
     * <p>获取java mapper class模板文件并替换字符串</p>
     *
     * @param Namespace
     * @param objName
     * @param FolderName
     * @param comments
     * @return
     */
    private String GetMapperString(String Namespace, String objName, String FolderName, String comments) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("mapper");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        OutString = OutString.replace("&comments&", comments);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy/MM/dd HH:mm"));
        return OutString;
    }

    /**
     * <p>获取crm Controller文件模板内容并替换关键字符串</p>
     *
     * @author yrf
     * @param Namespace
     * @param objName
     * @param FolderName
     * @param comments
     * @return
     */
    private String GetControllerString(String Namespace, String objName, String FolderName, String comments) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("controller");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        OutString = OutString.replace("&comments&", comments);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy/MM/dd HH:mm"));
        return OutString;
    }

    /**
     * <p>获取model文件模板并替换关键字符串</p>
     *
     * @param Namespace
     * @param objName
     * @param FolderName
     * @return
     */
    private String GetModelString(String Namespace, String objName, String FolderName, String comments) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("user");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        OutString = OutString.replace("&comments&", comments);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy/MM/dd HH:mm"));
        return OutString;
    }

    /**
     * <p>获取sql的xml映射文件模板并替换关键字符串</p>
     *
     * @author yrf
     * @param Namespace
     * @param objName
     * @param FolderName
     * @return
     */
    private String GetmapperxmlString(String Namespace, String objName, String FolderName) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("mapperxml");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;
    }

    /**
     * <p>获取jsp模板内容，并替换其中对象名称等信息</p>
     *
     * @param Namespace
     * @param objName
     * @param FolderName
     * @return
     */
    private String GetjspString(String Namespace, String objName, String FolderName) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("jsp");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;
    }

    /**
     * <p>获取other文件模板内容并替换关键字符串</p>
     *
     * @param Namespace
     * @param objName
     * @param FolderName
     * @return
     */
    private String GetotherString(String Namespace, String objName, String FolderName) {
        objName = toUpperCaseFirstOne(objName);
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent("other");
        OutString = OutString.replace("&package&", Namespace);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;

    }

    /**
     * <p>替换传入字符串的关键词为目标字符串</p>
     *
     * @param OutString  被替换字符串
     * @param Namespace
     * @param objName
     * @param FolderName
     * @return
     */
    private String PublicReplace(String OutString, String Namespace, String objName, String FolderName) {
        objName = toUpperCaseFirstOne(objName);
        String LobjName = toLowerCaseFirstOne(objName);
        OutString = OutString.replace("&package&", Namespace);
        OutString = OutString.replace("&objectname&", objName);
        OutString = OutString.replace("&LFobjectname&", LobjName);
        OutString = OutString.replace("&FolderName&", FolderName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;
    }

    /**
     * <p>根据传入文件名称获取模板内容并替换关键字符串</p>
     *
     * @param filename
     * @param Namespace
     * @param objName
     * @param FolderName
     * @param DisplayObjectName
     * @return
     */
    private String GetPublicReplaceFile(String filename, String Namespace, String objName, String FolderName,
                                        String DisplayObjectName) {
        BatchExportFileWriter writer = null;
        writer = new BatchExportFileWriter();
        String OutString = writer.gettemplateContent(filename);
        OutString = PublicReplace(OutString, Namespace, objName, FolderName);
        OutString = OutString.replace("&DisplayObjectName&", DisplayObjectName);
        CoreUser user = UserUtil.getUser();
        OutString = OutString.replace("&createdby&", user.getFirstName());
        OutString = OutString.replace("&created&", DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
        return OutString;
    }

    // 首字母转小写
    private static String toLowerCaseFirstOne(String sChar) {
        if (sChar == null || sChar.length() == 0) {
            return sChar;
        }
        if (Character.isLowerCase(sChar.charAt(0))) {
            return sChar;
        } else {
            return (new StringBuilder()).append(Character.toLowerCase(sChar.charAt(0)))
                    .append(sChar.substring(1)).toString();
        }
    }

    /**
     * <p>首字母转大写</p>
     *
     * @param sChar 待处理字符串
     * @return
     */
    private static String toUpperCaseFirstOne(String sChar) {
        if (sChar == null || sChar.length() == 0) {
            return sChar;
        }
        if (Character.isUpperCase(sChar.charAt(0))) {
            return sChar;
        } else {
            return (new StringBuilder()).append(Character.toUpperCase(sChar.charAt(0)))
                    .append(sChar.substring(1)).toString();
        }
    }

    /**
     * <p>格式化字符串，null返回""; 长度不足20空格补偿</p>
     *
     * @param sChar
     * @return
     */
    private String FormatStringToLength(String sChar) {
        if (sChar == null) {
            return "";
        }
        while (sChar.length() < 20) {
            sChar += " ";
        }
        return sChar;
    }

    /**
     * <p>格式化字符串，null返回""; 长度不足34空格补偿</p>
     *
     * @param sChar
     * @return
     */
    private String FormatStringToLength30(String sChar) {
        if (sChar == null) {
            return "";
        }
        while (sChar.length() < 34) {
            sChar += " ";
        }
        return sChar;
    }

    /**
     * <p>根据field对象生成移动端页面html对应字段代码</p>
     *
     * @author yrf
     * @param objname
     * @param field
     * @return
     */
    private String GetAppHtmlInfo(String objname, LnkInnerField field) {
        String tmp = "";
        objname = toLowerCaseFirstOne(objname);
        String uireadonly = field.getUireadonly();
        String DisplayName = field.getDisplayname();
        String appUIType = field.getAttr04();
        String readOnlyCondition = "";
        if (!StringUtils.isBlank(field.getAttr07())) {
            //app页面条件只读表达式
            readOnlyCondition = "ng-readonly=\"" + field.getAttr07() + "\" ";
        }
        if ("Y".equals(field.getAttr08()) && !StringUtils.isBlank(field.getAttr09())) {
            //多语言标记为Y，且多语言表达式不为空
            DisplayName = field.getAttr09();
        }
        String lov = field.getLovtype();
        if (StringUtils.isNull(lov)) {
            String placeholder = "Y".equals(uireadonly) || !"Y".equals(field.getAttr05()) ? "" : "请输入[DisplayName]";
            String closeicon = "Y".equals(field.getAttr06()) ? "closeicon" : "";
            if ("text".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' type='text' "
                        + closeicon + " class='text-input text-input--transparent' ng-user"
                        + "='[objname]Item.[field]' [readonly]></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("email".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' type='email' "
                        + closeicon + " class='text-input text-input--transparent' ng-user"
                        + "='[objname]Item.[field]' [readonly]></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("tel".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' type='tel' "
                        + closeicon + " class='text-input text-input--transparent' ng-user"
                        + "='[objname]Item.[field]' [readonly]></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("number".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' type='number' "
                        + closeicon + " class='text-input text-input--transparent' ng-user"
                        + "='[objname]Item.[field]' [readonly]></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("datetime".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' xday type='text' "
                        + closeicon + " class='text-input text-input--transparent' ng-user="
                        + "'[objname]Item.[field]' readonly ng-showdatepicker='datetime'></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("date".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle><input placeholder='"
                        + placeholder + "' xday type='text' "
                        + closeicon + " class='text-input text-input--transparent' ng-user"
                        + "='[objname]Item.[field]' readonly ng-showdatepicker='date'></ons-list-item>"
                        + System.getProperty("line.separator");
            } else if ("checkbox".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle>"
                        + "<label class='switch' style='margin-right: 20px !important;'>"
                        + "<input type='checkbox' class='switch__input' ng-user='[objname]Item.[field]'"
                        + "  ng-true-value=\"'Y'\" ng-false-value=\"'N'\">";
                tmp += "<div class='switch__toggle'>"
                        + " <span style='color: white;margin-left: 8px;position: absolute;margin-top: -9px;'"
                        + " ng-show=\"[objname]Item.[field]=='Y'\">Y ";
                tmp += "</span> <span style='color: #f3f3f3;margin-left: 24px;position: absolute;"
                        + "margin-top: -9px;' ng-show=\"[objname]Item.[field]=='N'"
                        + "|| [objname]Item.[field]==null'\">N </span>"
                        + "</div></label>";
                tmp += "</ons-list-item>" + System.getProperty("line.separator");
            } else if ("textarea".equals(appUIType)) {
                tmp = "<ons-list-item><mytitle [required]>[DisplayName]</mytitle>";
                tmp += "<textarea placeholder='" + placeholder + "' class='textarea textarea--transparent' "
                        + closeicon + "  ng-user='[objname]Item.[field]' rows='2'  >  </textarea></ons-list-item>"
                        + System.getProperty("line.separator");
            }
        } else {
            uireadonly = "Y";
            if (StringUtils.isNull(appUIType)) {
                appUIType = "text";
            }
            tmp += "<ons-list-item modifier='chevron' ng-click=\"!ItemPageIsReadOnly&&lovPick(\'lov\',"
                    + "[objname]ItemNavigator,lov.[lov],\'[DisplayName]\',\'[objname]Item.[field]\',null,true)\">"
                    + System.getProperty("line.separator");
            tmp += "<mytitle required>[DisplayName]</mytitle>" + System.getProperty("line.separator");
            tmp += "<input type='text' [required] placeholder='' class='text-input text-input--transparent'"
                    + " lov='[lov]'    ng-user='[objname]Item.[field]' [readonly]>"
                    + System.getProperty("line.separator");
            tmp += "</ons-list-item>" + System.getProperty("line.separator");
            tmp = tmp.replace("[lov]", lov);
        }
        String uireq = field.getUirequired();
        if ("Y".equals(uireq)) {
            tmp = tmp.replace("[required]", "required");
        } else {
            tmp = tmp.replace("[required]", "");
        }
        if ("Y".equals(uireadonly)) {
            tmp = tmp.replace("[readonly]", "readonly");
        } else {
            tmp = tmp.replace("[readonly]", readOnlyCondition);
        }
        String cfield = field.getName();
        tmp = tmp.replace("[DisplayName]", DisplayName);
        tmp = tmp.replace("[field]", cfield);
        tmp = tmp.replace("[objname]", objname);
        return tmp;
    }

    @Override
    public Map<String, String> newObjectFile(LnkInnerObject record) throws Exception {
        Map<String, String> result = new HashMap<>();
        List<FileExport> files = newObjectFile(record.getId());
        if (files == null || files.isEmpty()) {
            return result;
        }
        for (FileExport file : files) {
            result.put(file.getPath(), file.getTxtContent());
        }
        return result;
    }


    @Override
    public List<FileExport> newObjectFile(Long id) throws Exception {
        if (id == null) {
            throw new ServiceException("id 不允许为空");
        }
        LnkInnerObject record = new LnkInnerObject();
        record.setId(id);
        List<FileExport> result = new ArrayList<>();
        List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(record);
        for (LnkInnerObject header : headers) {

            String modelName = toUpperCaseFirstOne(header.getName());
            //crm包名
            String namespace = header.getAttr04().toLowerCase();
            //文件夹名称
            String FolderName = header.getAttr03().toLowerCase();
            if (StringUtils.isBlank(header.getAttr01())) {
                header.setAttr01("");
            }
            if (StringUtils.isBlank(header.getComs())) {
                header.setComs("");
            }
            String comments = header.getAttr01() + "-" + header.getComs();
            /* 处理各种文件头 */
            //定义存放mapper的变量
            String sqlMapper = GetMapperString(namespace, modelName, FolderName, comments);
            //定义service的变量
            String servicejava = GetServiceString(namespace, modelName, FolderName, comments);
            //定义存放service实现的变量
            String serviceImpjava = GetServiceImplString(namespace, modelName, FolderName, comments);
            //定义存放controller的变量
            String Controllerjava = GetControllerString(namespace, modelName, FolderName, comments);
            //定义存放对象的变量
            String ModelString = GetModelString(namespace, modelName, FolderName, comments);
            //定义存放旧版本jsp的变量
            String Jspfile = this.genJspListContent(header);
            //定义存放其他txt文本的变量
            String otherTxt = GetotherString(namespace, modelName, FolderName);
            //定义存放新版本easyui的变量
            String HTMLfile = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/templateHTML.html");
            //定义存放vue的列表html模板 20180520
            String vueHTMLList = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/templateList.html");
            //定义存放vue的表单的模板
            String vueHTMLForm = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/templateDetail.html");
            //定义存放css的列表的模板
            String vueCSSList = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/css/templateList.css");
            //定义存放css的表单模板
            String vueCSSForm = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/css/templateDetail.css");
            //定义存放js的列表的模板
            String vueJSList = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/js/templateList.js");
            //定义存放表单的js的模板
            String vueJSForm = GetPublicTemplateString(namespace, modelName, FolderName, "/crm/linkcrm/js/templateDetail.js");

            header = getFullLnkInnerObjectById(header);
            /*LnkInnerLink linkExample = new LnkInnerLink();
            linkExample.setParentid(record.getId());
            linkExample.setAttr02("Y");//有效关联表
            linkExample.setPageFlag(false);
            List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(linkExample);// query

            LnkInnerField fieldExample = new LnkInnerField();
            fieldExample.setParentid(record.getId());
            fieldExample.setAttr02("Y");//有效字段
            fieldExample.setPageFlag(false);
            List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(fieldExample);// query
            header.setFieldList(fields);
            header.setLinkList(links);

            LnkInnerWhere whereExample = new LnkInnerWhere();
            whereExample.setParentid(record.getId());
            List<LnkInnerWhere> wheres = lnkInnerWhereMapper.queryByInner(whereExample);
            header.setWhereList(wheres);

            header.setFullObjFlag(true);*/
            // List<LnkInnerWhere> wheres = header.getWhereList();
            List<LnkInnerField> fields = header.getFieldList();
            // List<LnkInnerLink> links = header.getLinkList();
            /* 处理基表的字段 */
            //model的字段
            String modelFields = "";
            //model的setter getter
            String modelFields2 = "";
            String lastCreatedString = header.getCreated(10).substring(0, 10);
            String lastCreatedByName = header.getCreatedByName();
            //定义存放导出json配置的变量
            String exportJSONConfig = "Object.freeze(JSON.parse('[{\"field\":\"Id\",\"title\":\"编码\",\"order\":0}";
            for (LnkInnerField field : fields) {
                if (!"Y".equals(field.getActiveflag())) {
                    continue;
                }
                String createdByInfo = "";
                String createdString = field.getCreated(10).substring(0, 10);
                if (!StringUtils.equals(lastCreatedString, createdString)) {
                    lastCreatedString = createdString;
                    createdByInfo = System.getProperty("line.separator") + "    /**created:"
                            + createdString + ",createdBy:" + field.getCreatedByName()
                            + "*/" + System.getProperty("line.separator");
                }
                if (!StringUtils.equals(lastCreatedByName, field.getCreatedByName())) {
                    lastCreatedByName = field.getCreatedByName();
                    createdByInfo = System.getProperty("line.separator") + "    /**created:"
                            + createdString + ",createdBy:"
                            + field.getCreatedByName() + "*/" + System.getProperty("line.separator");
                }
                /* 处理model字段 */
                String lov = field.getLovtype();
                String cfield = field.getName();
                String fieldtype = field.getFieldtype();
                //当不是同一天新建的字段时，增加上日期和创建者的备注，
                if (!"".equals(createdByInfo)) {
                    modelFields += createdByInfo;
                    modelFields2 += createdByInfo;

                }
                exportJSONConfig += ",{\"field\":\"" + cfield + "\",\"title\":\""
                        + field.getDisplayname() + "\",\"order\":" + field.getSeq() + "}";
                if (StringUtils.isNull(lov)) {
                    modelFields += "    /**" + field.getDisplayname() + "*/"
                            + System.getProperty("line.separator")
                            + "    private " + fieldtype + " " + FormatStringToLength(cfield + ";")
                            +  System.getProperty("line.separator") ;
                } else {
                    modelFields += "    /**" + field.getDisplayname() + ",值列表类型: " + lov + " */"
                            + System.getProperty("line.separator")
                            + "    private " + fieldtype + " " + FormatStringToLength(cfield + ";")
                            +  System.getProperty("line.separator") ;
                }
                String UFfield = toUpperCaseFirstOne(cfield);
                modelFields2 += "    public " + fieldtype + " get" + UFfield + "() {"
                        + System.getProperty("line.separator");
                modelFields2 += "        return " + cfield + ";" + System.getProperty("line.separator");
                modelFields2 += "    }" + System.getProperty("line.separator") + System.getProperty("line.separator");
                modelFields2 += "    public void set" + UFfield + "(" + fieldtype + " " + cfield + ") {"
                        + System.getProperty("line.separator");
                modelFields2 += "        this." + cfield + " = " + cfield + ";" + System.getProperty("line.separator");
                modelFields2 += "    }" + System.getProperty("line.separator") + System.getProperty("line.separator");
            }
            exportJSONConfig += "]'));";
            vueJSList = vueJSList.replace("&exportJSONConfig&", exportJSONConfig);

            ModelString = ModelString.replace("&modelFields&", modelFields + System.getProperty("line.separator")
                    + System.getProperty("line.separator") + modelFields2);


            String LFmodelName = toLowerCaseFirstOne(modelName);
            String UFmodelName = toUpperCaseFirstOne(modelName);
            // 生成oracle sqlmapper
            String oracleSqlMapper = newSqlMapper(header, "oracle", false);
            // 生成 MySQL sqlmapper
            String mySqlMapper = newSqlMapper(header, "mysql", false);

            Map<String, String> regexMap = new HashMap<>();
            regexMap.put("${FolderName}", FolderName);
            regexMap.put("${UFmodelName}", UFmodelName);
            regexMap.put("${LFmodelName}", LFmodelName);
            String oracleSqlMapperPath = StringTool.replaceAll("crm.${FolderName}.dao.mybatis.sqlMap.${UFmodelName}Mapper#xml", regexMap);
            result.add(new FileExport(CodeTypeEnum.XML_MAPPER_ORACLE, oracleSqlMapperPath, oracleSqlMapper));

            String mySqlMapperPath = StringTool.replaceAll("crm.${FolderName}.dao.mybatis.sqlMap.${UFmodelName}MapperMySql#xml", regexMap);
            result.add(new FileExport(CodeTypeEnum.XML_MAPPER_MYSQL, mySqlMapperPath, mySqlMapper));

            String sqlMapperPath = StringTool.replaceAll("crm.${FolderName}.dao.mybatis.mapper.${UFmodelName}Mapper#java", regexMap);
            result.add(new FileExport(CodeTypeEnum.JAVA_MAPPER,sqlMapperPath, sqlMapper));

            String ModelStringPath = StringTool.replaceAll("crm.${FolderName}.model.${UFmodelName}#java", regexMap);
            result.add(new FileExport(CodeTypeEnum.JAVA_MODEL,ModelStringPath, ModelString));

            String servicejavaPath = StringTool.replaceAll("crm.${FolderName}.service.${UFmodelName}Service#java", regexMap);
            result.add(new FileExport(CodeTypeEnum.JAVA_SERVICE,servicejavaPath, servicejava));

            String serviceImpjavaPath = StringTool.replaceAll("crm.${FolderName}.service.${UFmodelName}ServiceImpl#java", regexMap);
            result.add(new FileExport(CodeTypeEnum.JAVA_SERVICE_IMPL,serviceImpjavaPath, serviceImpjava));

            String ControllerjavaPath = StringTool.replaceAll("crm.${FolderName}.controller.${UFmodelName}Controller#java", regexMap);
            result.add(new FileExport(CodeTypeEnum.JAVA_CONTROLLER,ControllerjavaPath, Controllerjava));

            String JspfilePath = StringTool.replaceAll("crm.portal.${LFmodelName}List#jsp", regexMap);
            result.add(new FileExport(CodeTypeEnum.JSP_LIST,JspfilePath, Jspfile));
            result.add(new FileExport(CodeTypeEnum.TXT_OTHER,"crm.otherTXT" + RANDOM.nextInt(100) + "#txt", otherTxt));

            //定义存放新版本easyui的变量
            String HTMLfilePath = StringTool.replaceAll("crm.portal.${LFmodelName}List#html", regexMap);
            result.add(new FileExport(CodeTypeEnum.HTML_LIST_EASYUI,HTMLfilePath, HTMLfile));

            String vueHTMLListPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.${LFmodelName}List#html", regexMap);
            result.add(new FileExport(CodeTypeEnum.HTML_LIST_VUE,vueHTMLListPath, vueHTMLList));
            //定义存放vue的表单的模板
            String vueHTMLFormPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.${LFmodelName}Detail#html", regexMap);
            result.add(new FileExport(CodeTypeEnum.HTML_DETAIL_VUE,vueHTMLFormPath, vueHTMLForm));
            //定义存放css的列表的模板
            String vueCSSListPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.css.${LFmodelName}List#css", regexMap);
            result.add(new FileExport(CodeTypeEnum.CSS_LIST_VUE,vueCSSListPath, vueCSSList));
            //定义存放css的表单模板
            String vueCSSFormPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.css.${LFmodelName}Detail#css", regexMap);
            result.add(new FileExport(CodeTypeEnum.CSS_DETAIL_VUE, vueCSSFormPath, vueCSSForm));
            //定义存放js的列表的模板
            String vueJSListPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.js.${LFmodelName}List#js", regexMap);
            result.add(new FileExport(CodeTypeEnum.JS_LIST_VUE, vueJSListPath, vueJSList));
            //定义存放js表单模板
            String vueJSFormPath = StringTool.replaceAll("crm.linkcrm.${LFmodelName}.js.${LFmodelName}Detail#js", regexMap);
            result.add(new FileExport(CodeTypeEnum.JS_DETAIL_VUE, vueJSFormPath, vueJSForm));
        }
        return result;
    }

    @Override
    public String Check(LnkInnerObject record) throws Exception {
        return "test";
    }

    @Override
    public void DeepCopy(LnkInnerObject record) throws Exception {
        System.out.println("start deep copy");
        System.out.println(record.getId());
        List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(record);
        for (LnkInnerObject header : headers) {
            System.out.println("found");
            Long headerId = keyGenerateService.keyGenerate();
            header.setId(headerId);
            lnkInnerObjectMapper.insert(header);
            System.out.println("inserted");
            LnkInnerLink qps1 = new LnkInnerLink();
            qps1.setParentid(record.getId());
            LnkInnerField qps2 = new LnkInnerField();
            qps2.setParentid(record.getId());
            LnkInnerWhere qps3 = new LnkInnerWhere();
            qps3.setParentid(record.getId());
            List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(qps1);
            List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(qps2);
            List<LnkInnerWhere> wheres = lnkInnerWhereMapper.queryByInner(qps3);
            for (LnkInnerField field : fields) {
                field.setId(keyGenerateService.keyGenerate());
                field.setParentid(headerId);
                lnkInnerFieldMapper.insert(field);
            }
            for (LnkInnerLink link : links) {
                link.setId(keyGenerateService.keyGenerate());
                link.setParentid(headerId);
                lnkInnerLinkMapper.insert(link);
            }
            for (LnkInnerWhere where : wheres) {
                where.setId(keyGenerateService.keyGenerate());
                where.setParentid(headerId);
                lnkInnerWhereMapper.insert(where);
            }
        }
    }

    @Override
    public void getmodelinfo(LnkInnerObject record) throws Exception {
//        AutoLoadProject ap = new AutoLoadProject();
        AutoLoadProject.ReadAllJSPFileAndGetModel();
        List<LnkInnerObject> headers = AutoLoadProject.finalHeader;
        for (LnkInnerObject row : headers) {
            Long id = keyGenerateService.keyGenerate();
            row.setId(id);
            lnkInnerObjectMapper.insert(row);

        }
    }

    @Override
    public void updatemodelinfo(LnkInnerObject record) throws Exception {
        List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(record);
        for (LnkInnerObject header : headers) {
            if (header.getAttr05() == null || header.getAttr06() == null || header.getAttr08() == null) {
                continue;
            }
            if ("".equals(header.getAttr05()) || "".equals(header.getAttr06()) || "".equals(header.getAttr08())) {
                continue;
            }
            String modelFile = header.getAttr05();
            String jspFile = header.getAttr06();
            String jspTable = header.getAttr08();
            String xmlfile = header.getAttr07();
            String xmlMapperId = header.getAttr15();
            AutoLoadProject ap = new AutoLoadProject();
            AutoLoadProject.GetJspAllFileInfo(modelFile, jspFile, jspTable, xmlfile, xmlMapperId);
            LnkInnerField qps = new LnkInnerField();
            qps.setParentid(header.getId());
            List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(qps);
            List<LnkInnerField> fields2 = AutoLoadProject.finalLF;
            for (LnkInnerField fieldi : fields2) {
                Boolean Found = false;
                String fname2 = fieldi.getName();
                for (LnkInnerField field : fields) {
                    String fname = field.getName();
                    if (fname != null) {
                        if (fname2 != null) {
                            if (StringUtils.equals(fname, fname2)) {
                                fieldi.setId(field.getId());
                                fieldi.setParentid(header.getId());
                                lnkInnerFieldMapper.update(fieldi);
                                Found = true;
                            }
                        }
                    }
                }
                if (!Found) {
                    fieldi.setId(keyGenerateService.keyGenerate());
                    fieldi.setParentid(header.getId());
                    lnkInnerFieldMapper.insert(fieldi);
                    ;
                }
            }
            LnkInnerLink qps1 = new LnkInnerLink();
            qps1.setParentid(header.getId());
            // sql_tbmap
            List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(qps1);
            for (LnkInnerLink link : links) {
                // delete all
                lnkInnerLinkMapper.deleteById(link);
            }
            Iterator it = AutoLoadProject.sql_tbmap.entrySet().iterator();
            int cnt = AutoLoadProject.sql_tbmap.size();
            int n = 0;
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                Object key = entry.getKey();
                String TableName = key.toString();
                String wherestring = "";
                if (n == cnt - 1) {
                    wherestring = ap.GetOneWhere(TableName, true);
                } else {
                    wherestring = ap.GetOneWhere(TableName, false);
                }
                n++;
                LnkInnerLink link = new LnkInnerLink();
                link.setId(keyGenerateService.keyGenerate());
                link.setParentid(header.getId());
                Object value = entry.getValue();
                String TableVaue = value.toString();
                link.setName(TableName + "_" + TableVaue);
                link.setTablename(TableVaue);
                link.setLinkcoms(wherestring);
                link.setOuterflag("Y");
                link.setAttr01(TableName);
                lnkInnerLinkMapper.insert(link);
            }
        }
    }

    /**
     * <p>获取完整对象信息，包括头，字段对象列表、关联表对象列表</p>
     *
     * @author yrf
     * @param example
     * @return obj
     * @throws Exception 异常
     */
    @Override
    public LnkInnerObject getFullLnkInnerObjectById(LnkInnerObject example) throws Exception {
        if (example == null || null == example.getId()) {
            throw new Exception("对象id不能为空");
        }
        LnkInnerObject obj = lnkInnerObjectMapper.queryById(example);
        if (obj == null) {
            throw new Exception("查询对象结果为空[" + example.getId());
        }
        /** 获取关联表对象信息 */
        LnkInnerLink linkExample = new LnkInnerLink();
        linkExample.setParentid(example.getId());
        linkExample.setPageFlag(false);
        //有效关联表
        linkExample.setAttr02("Y");
        List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(linkExample);// query
        obj.setLinkList(links);

        /** 获取字段信息 */
        LnkInnerField fieldExample = new LnkInnerField();
        fieldExample.setParentid(example.getId());
        fieldExample.setPageFlag(false);
        //有效字段
        fieldExample.setAttr02("Y");
        List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(fieldExample);// query
        obj.setFieldList(fields);

        LnkInnerWhere whereExample = new LnkInnerWhere();
        whereExample.setParentid(example.getId());
        // 有效条件
        whereExample.setAttr02("Y");
        List<LnkInnerWhere> wheres = lnkInnerWhereMapper.queryByInner(whereExample);
        obj.setWhereList(wheres);

        obj.setFullObjFlag(true);
        return obj;
    }

    /**
     * <p>根据模板生成CRM Jsp List 文件内容</p>
     *
     * @author yrf
     * @param header
     * @return string
     * @throws Exception
     */
    public String genJspListContent(LnkInnerObject header) throws Exception {
        if (!header.getFullObjFlag()) {
            //当前对象下的字段、关联表信息是否已经设置
            header = getFullLnkInnerObjectById(header);
        }
        String jspFastSearch = "";
        String jspKeyScript = "";
        jspFastSearch += "    <fieldset class=\"x-fieldset\" id=\"keyFilter\">"
                + System.getProperty("line.separator");
        jspFastSearch += "        <legend class=\"x-fieldset-header\""
                + " style=\"width: 95px; margin-bottom: 0px; border: none;\">"
                + System.getProperty("line.separator");
        jspFastSearch += "            <span class=\"x-fieldset-title\">快速筛选</span></legend>"
                + System.getProperty("line.separator");
        Boolean haveFastSearch = false;
        String jspFields = "";
        jspFields += "                <th field=\"id\" width=\"100px\" >编号</th>" + System.getProperty("line.separator");
        jspFields += "                <th field=\"created\" width=\"100px\" >创建时间</th>"
                + System.getProperty("line.separator");

        String jspFileContentContentContentContent = "";
        /* 处理各种文件头 */
        String modelName = toUpperCaseFirstOne(header.getName());
        //crm包名
        String namespace = header.getAttr04().toLowerCase();
        //文件夹名称
        String FolderName = header.getAttr03().toLowerCase();
        jspFileContentContentContentContent = GetjspString(namespace, modelName, FolderName);

        List<LnkInnerField> fields = header.getFieldList();
        for (LnkInnerField field : fields) {
            if (!"Y".equals(field.getActiveflag())) {
                continue;
            }
            /* 处理model字段 */
            //值列表类型
            String lov = field.getLovtype();
            //字段名称
            String fieldName = field.getName();
            //显示名称
            String displayName = field.getDisplayname();
            if ("Y".equals(field.getAttr08()) && !StringUtils.isBlank(field.getAttr09())) {
                //多语言表达式
                displayName = field.getAttr09();
            }
            //String UFfield = toUpperCaseFirstOne(fieldName);
            //String fieldtype = field.getFieldtype();//字段类型--java
            //默认搜索
            String defaultSearch = "false";
            //页面必填
            String uiReq = "Y".equals(field.getUirequired()) ? "true" : "false";
            //界面类型
            String uiType = field.getUitype();
            //页面可查询
            String uiQuery = "Y".equals(field.getUiqueryflag()) ? "false" : "true";
            StringBuffer strb = new StringBuffer();
            strb.append("                <th field=\"" + fieldName + "\" noSearch=\""
                    + uiQuery + "\" defaultSearch=\"" + defaultSearch + "\" ");

            if ("Y".equals(field.getUireadonly())) {
                //界面只读
                if (!StringUtils.isBlank(lov)) {
                    //值列表不为空
                    strb.append("lov=\"" + lov + "\" width=\"100px\" ");
                }

            } else {
                //界面可编辑
                if (!StringUtils.isBlank(lov)) {
                    //值列表不为空
                    strb.append("lov=\""
                            + lov + "\" width=\"100px\" editor=\"{type:'combobox',options:{valueField:'val',"
                            + System.getProperty("line.separator")
                            + "                textField:'name',data:getLovArray('"
                            + lov + "'),editable:false,required:"
                            + uiReq + "}}\" ");
                } else if ("checkbox".equals(uiType)) {
                    strb.append(" width=\"60px\" editor=\"{type:'checkbox',options:{on:'Y',off:'N'}}\" ");
                } else if ("datebox".equals(uiType)) {
                    strb.append(" width=\"100px\" editor=\"{type:'datebox',options:{showSeconds:false, "
                            + System.getProperty("line.separator")
                            + "required:" + uiReq + "}}\" ");
                } else if ("datetimebox".equals(uiType)) {
                    strb.append(" width=\"120px\" editor=\"{type:'datetimebox',options:{showSeconds:false, "
                            + System.getProperty("line.separator")
                            + "required:" + uiReq + "}}\" ");
                } else if ("validatebox".equals(uiType)) {
                    strb.append("  width=\"100px\" editor=\"{type:'validatebox',options:{required:" + uiReq + "}}\" ");
                } else if ("numberbox".equals(uiType)) {
                    strb.append(" width=\"100px\" editor=\"{type:'numberbox',options:{required:" + uiReq + "}}\" ");
                } else if ("textarea".equals(uiType)) {
                    strb.append(" width=\"100px\" editor=\"{type:'textarea',options:{required:" + uiReq + "}}\" ");
                } else {
                    strb.append(" width=\"100px\" editor=\"{type:'textbox',options:{required:" + uiReq + "}}\" ");
                }
            }
            strb.append(" >" + displayName + "</th>" + System.getProperty("line.separator"));
            jspFields += strb.toString();

            if ("Y".equals(field.getAttr03()) && !StringUtils.isBlank(lov)) {
                // 快速筛选
                haveFastSearch = true;
                jspFastSearch += "";
                jspFastSearch += "                <div class=\"row keyfilter-border\">"
                        + System.getProperty("line.separator");
                jspFastSearch += "                    <ul id=\"" + field.getName()
                        + "Keyfilter\" data-toggle=\"keyfilter\" data-title=\"" + displayName
                        + "\" data-filter-filed=\"" + field.getName() + "\""
                        + System.getProperty("line.separator");
                jspFastSearch += "data-table-Id=\"" + toLowerCaseFirstOne(header.getName()) + "-table\"></ul></div>"
                        + System.getProperty("line.separator");
                jspKeyScript += "        $('#" + field.getName()
                        + "Keyfilter').keyFilter({remoteData:true,filterByValue:true,remoteUrl:"
                        + "'${AppContext.ctxPath}/action/link/basic/list/"
                        + lov + "'});" + System.getProperty("line.separator");
            }
        }
        if (haveFastSearch) {
            jspFastSearch = jspFastSearch + System.getProperty("line.separator") + "</fieldset>"
                    + System.getProperty("line.separator");
        } else {
            jspKeyScript = "";
            jspFastSearch = "";
        }
        jspFileContentContentContentContent = jspFileContentContentContentContent.replace("&jspFields&", jspFields);
        jspFileContentContentContentContent =
                jspFileContentContentContentContent.replace("&jspKeyScript&", jspKeyScript);
        jspFileContentContentContentContent =
                jspFileContentContentContentContent.replace("&jspFastSearch&", jspFastSearch);

        return jspFileContentContentContentContent;
    }

    @Override
    public String test(LnkInnerObject record) throws Exception {
        // TODO Auto-generated method stub
        return genJspListContent(record);
    }

    @Override
    public String newSqlMapper(LnkInnerObject record, String dataBaseType, boolean genIfTestTag) throws Exception {
        String lastCreatedString = record.getCreated(10).substring(0, 10);
        String lastCreatedByName = record.getCreatedByName();
        /* * 保存必有的列名* 生成sql时防止重复生成*/
        Map<String, String> systemField = new HashMap<String, String>();
        systemField.put("id", "");
        systemField.put("created", "");
        systemField.put("createdBy", "");
        systemField.put("lastUpdated", "");
        systemField.put("lastUpdatedBy", "");
        systemField.put("corpid", "");
        systemField.put("orgId", "");
        systemField.put("postnId", "");
        LnkInnerObject header = record;
        if (!header.getFullObjFlag()) {
            header = getFullLnkInnerObjectById(record);
        }
        //List<LnkInnerObject> headers = lnkInnerObjectMapper.queryByInner(record);
        /*保存已生成sql的列名，生成sql时防止重复生成*/
        Map<String, String> lineField = new HashMap<String, String>();
        String selectallsql = "";
        String insertintosql = "INSERT INTO " + header.getBasetable() + "(" + System.getProperty("line.separator")
                + "         " + FormatStringToLength("ROW_ID")
                + "/*记录ID*/" + System.getProperty("line.separator");
        String deletefromsql = "";
        String updatemiddle = "";
        // 插入字段--列名称
        String insertField = "";
        // 插入列数据值--
        String insertValue = System.getProperty("line.separator") + "         " + FormatStringToLength("#{id}")
                + "/*记录ID*/" + System.getProperty("line.separator");
        deletefromsql = "DELETE FROM " + header.getBasetable() + " WHERE ROW_ID=#{id} AND CORP_ID=#{loginCorpId}";
        selectallsql = System.getProperty("line.separator")
                + "         " + FormatStringToLength("T1.ROW_ID") + " as " + FormatStringToLength("id")
                + "/*记录编号*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.CREATED") + " as "
                + FormatStringToLength("created") + "/*创建时间*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.CREATED_BY") + " as " + FormatStringToLength("createdBy")
                + "/*创建者ID*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.LAST_UPD") + " as "
                + FormatStringToLength("lastUpdated") + "/*最后更新时间*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.LAST_UPD_BY") + " as "
                + FormatStringToLength("lastUpdatedBy") + "/*最后更新者ID*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.CORP_ID") + " as " + FormatStringToLength("corpid")
                + "/*公司账套*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.ORG_ID") + " as " + FormatStringToLength("orgId")
                + "/*组织ID*/" + System.getProperty("line.separator")

                + "        ," + FormatStringToLength("T1.POSTN_ID") + " as " + FormatStringToLength("postnId")
                + "/*职位ID*/" + System.getProperty("line.separator");

        /* 处理各种文件头 */

        String sqlMapxml = "";
        String modelName = toUpperCaseFirstOne(header.getName());
        //crm包名
        String namespace = header.getAttr04().toLowerCase();
        //文件夹名称
        String FolderName = header.getAttr03().toLowerCase();
        sqlMapxml = GetmapperxmlString(namespace, modelName, FolderName);

        LnkInnerWhere lnkInnerWhere = new LnkInnerWhere();
        lnkInnerWhere.setParentid(record.getId());
        lnkInnerWhere.setAttr02("Y");
        List<LnkInnerWhere> lnkInnerWheres = lnkInnerWhereMapper.queryByInner(lnkInnerWhere);
        String LinkString;
        String whereString = "    WHERE 1=1" + System.getProperty("line.separator");
        if (!lnkInnerWheres.isEmpty() && !StringUtils.isBlank(lnkInnerWheres.get(0).getLinkcoms())) {
            //兼容之前版本，取第一个from语句
            String fromSql = lnkInnerWheres.get(0).getLinkcoms();
            LinkString = fromSql + System.getProperty("line.separator") + whereString;
        } else {
            LinkString = "    FROM     " + FormatStringToLength(header.getBasetable()) + " "
                    + header.getBasetablealais() + System.getProperty("line.separator") + whereString;
        }


        //List<LnkInnerField> fields = lnkInnerFieldMapper.queryByInner(fieldExample);// query
        //List<LnkInnerLink> links = lnkInnerLinkMapper.queryByInner(linkExample);// query

        List<LnkInnerField> fields = header.getFieldList();
        List<LnkInnerLink> links = header.getLinkList();
        /*header.setFieldList(fields);
        header.setLinkList(links);
        header.setFullObjFlag(true);*/
        /* 处理基表的字段 */
        //String modelFields = "";
        //String modelFields2 = "";
        // 当前是第几个字段，第一个字段前面不用逗号。。。
        int fieldcount = 0;
        for (LnkInnerField field : fields) {
            if (!"Y".equals(field.getActiveflag()) || !"Y".equals(field.getAttr02())) {
                continue;
            }
            // 创建人注释信息
            String createdByInfo = "";
            // 创建时间注释信息
            String createdString = field.getCreated(10).substring(0, 10);
            // 更新时间不等于创建时间，说明字段后面加的，添加注释
            if (!StringUtils.equals(lastCreatedString, createdString)) {
                lastCreatedString = createdString;
                createdByInfo = System.getProperty("line.separator") + "    /*created:"
                        + createdString + ",createdBy:" + field.getCreatedByName() + "*/"
                        + System.getProperty("line.separator");
            }
            // 更新人不等于创建人，添加注释
            if (!StringUtils.equals(lastCreatedByName, field.getCreatedByName())) {
                lastCreatedByName = field.getCreatedByName();
                createdByInfo = System.getProperty("line.separator") + "    /*created:"
                        + createdString + ",createdBy:" + field.getCreatedByName() + "*/"
                        + System.getProperty("line.separator");
            }

            if (!"".equals(createdByInfo)) {
                insertField += createdByInfo;
                insertValue += createdByInfo;
                updatemiddle += createdByInfo;
                selectallsql += createdByInfo;
            }

            /* 处理model字段 */
            String cfield = field.getName();
            String ifPrefix = "";
            String ifSuffix = "";
            // 若要生成if test标签判断
            if (genIfTestTag) {
                ifPrefix = "        <if test=\"" + cfield + "!=null and "
                        + cfield + "!=''\">" + System.getProperty("line.separator");
                ifSuffix = System.getProperty("line.separator") + "        </if>";
            }
            if (!StringUtils.isNull(field.getJoinname())) {
                continue;
            }
            if (systemField.containsKey(field.getName())) {
                continue;
            }
            if (lineField.containsKey(field.getName())) {
                continue;
            }
            fieldcount++;
            /* 处理insert 和update */
            String scol = scol = "T1." + field.getColumnname();
            String scol2 = "";
            // scol = "T1." + field.getColumnname();
            // scol2 = "#{" + cfield + "}";
            String lov = field.getLovtype();
            if ("DATE".equals(field.getColumntype())) {
                if ("mysql".equals(dataBaseType)) {
                    scol2 = "str_to_date(#{" + cfield + "},'%Y-%m-%d %H:%i:%S')";
                } else {
                    // oracle 时间格式转换
                    scol2 = "TO_DATE(#{" + cfield + "},'YYYY-MM-DD HH24:MI')";
                }
            } else if (StringUtils.isNotBlank(lov)) {
                // 值列表转换
                scol2 = "GET_LOV_VAL(#{loginCorpId},'" + lov + "',#{" + cfield + "})";
            } else {
                scol2 = "#{" + cfield + "}";
            }
            if (fieldcount == 1) {
                updatemiddle += "         " + FormatStringToLength(field.getColumnname()) + "="
                        + FormatStringToLength(scol2) + "/*" + field.getDisplayname() + "*/"
                        + System.getProperty("line.separator");
            } else {
                updatemiddle += ifPrefix
                        + "        ," + FormatStringToLength(field.getColumnname()) + "="
                        + FormatStringToLength(scol2) + "/*" + field.getDisplayname() + "*/"
                        + ifSuffix
                        + System.getProperty("line.separator");
            }
            insertField += ifPrefix
                    + "        ," + FormatStringToLength(field.getColumnname()) + "/*" + field.getDisplayname() + "*/"
                    + ifSuffix
                    + System.getProperty("line.separator");
            insertValue += ifPrefix
                    + "        ," + FormatStringToLength(scol2) + "/*" + field.getDisplayname() + "*/"
                    + ifSuffix
                    + System.getProperty("line.separator");
            selectallsql += "        ," + FormatStringToLength(scol) + " as " + FormatStringToLength(field.getName())
                    + "/*" + field.getDisplayname() + "*/" + System.getProperty("line.separator");
            /** 暂时不用生成<if test/> **/
            /*
             * where2 += "        <if test=\"" + cfield + " != null and " +
             * cfield + " != '' \">" + System.getProperty("line.separator");
             * where2 += "            and T1." + field.getColumnname() + scol2 +
             * System.getProperty("line.separator"); where2 += "        </if>" +
             * System.getProperty("line.separator");
             */
            lineField.put(field.getName(), "");
        }
//        for (LnkInnerLink link : links) {
//            String linkname = link.getName();
//            if (!"Y".equals(link.getAttr02())) {
//                continue;
//            }
//            LinkString += "        ," + link.getTablename() + " " + link.getAttr01()
//                    + System.getProperty("line.separator");
//            whereString += "        AND (" + link.getLinkcoms() + ")" + System.getProperty("line.separator");
//            for (LnkInnerField field : fields) {
//                String fieldlinname = field.getJoinname();
//                if (!"Y".equals(field.getActiveflag())) {
//                    continue;
//                }
//                if (!StringUtils.equals(linkname, fieldlinname) || StringUtils.isNull(fieldlinname)) {
//                    continue;
//                }
//                if (systemField.containsKey(field.getName())) {
//                    continue;
//                }
//                if (lineField.containsKey(field.getName())) {
//                    continue;
//                }
//                String lov = field.getLovtype();
//                String cfield = field.getName();
//                String scol = "";
//                String scol2 = "";
//                // scol = link.getAttr01() + "." + field.getColumnname();
//                // scol2 = "#{" + cfield + "}";
//                if (StringUtils.isNull(lov)) {
//                    scol = link.getAttr01() + "." + field.getColumnname();
//                    scol2 = "#{" + cfield + "}";
//                } else {
//                    scol = link.getAttr01() + "." + field.getColumnname();
//                    scol2 = "GET_LOV_VAL(#{loginCorpId},'" + lov + "',#{" + cfield + "})";
//                }
//                selectallsql += "        ," + FormatStringToLength(scol) + " as "
//                        + FormatStringToLength(field.getName()) + "/*" + field.getDisplayname() + "*/"
//                        + System.getProperty("line.separator");
//                lineField.put(field.getName(), "");
//            }
//        }
//        LnkInnerWhere whereExample = new LnkInnerWhere();
//        whereExample.setParentid(record.getId());
//        List<LnkInnerWhere> wheres = header.getWhereList();
//        for (LnkInnerWhere where : wheres) {
//            String whereComs = where.getLinkcoms();
//            if (!StringUtils.isBlank(whereComs) && "Y".equals(where.getAttr02())) {
//                if (whereComs.trim().startsWith("<") || whereComs.trim().toUpperCase().startsWith("AND ")) {
//                    whereString += "        " + where.getLinkcoms() + "" + System.getProperty("line.separator");
//                } else {
//                    whereString += "        AND " + where.getLinkcoms() + "" + System.getProperty("line.separator");
//                }
//            }
//        }
        insertintosql += insertField + "        ) values (" + System.getProperty("line.separator") + insertValue
                + "        )";

        String updatesql = "UPDATE " + header.getBasetable() + " SET" + System.getProperty("line.separator")
                + updatemiddle + "        WHERE ROW_ID=#{id}";

        String fromTableSql = "";
        fromTableSql = LinkString + System.getProperty("line.separator");

//        String originSql = "select \n" + selectallsql + "\n" + LinkString + "\n" + whereString;
//        System.out.println("autoConfig->originOracleSql:");
//        System.out.println(originSql);
//        LinkStatement linkStatement = new LinkStatement();
//        Map<String, String> transformResultMap = linkStatement.transformOracleQueryToMySql(originSql);
//        String mysqlFromTableSql = transformResultMap.get("fromClause") + "\n" + "    where 1=1 \n";
        sqlMapxml = sqlMapxml.replace("&selectallsql&", selectallsql);
        sqlMapxml = sqlMapxml.replace("&fromTableSql&", fromTableSql);
//        if (!"mysql".equals(dataBaseType)) {
//        } else {
//            sqlMapxml = sqlMapxml.replace("&fromTableSql&", mysqlFromTableSql);
//        }
        String where2 = "";
        String whereAllSql = "";
        String orderbysqll = "";
//        where2 = transformResultMap.get("whereClause").replace("where 1 = 1","");
        sqlMapxml = sqlMapxml.replace("&whereAllSql&", whereAllSql + System.getProperty("line.separator") + where2);
        sqlMapxml = sqlMapxml.replace("&orderbysqll&", orderbysqll);
        sqlMapxml = sqlMapxml.replace("&insertintosql&", insertintosql);
        sqlMapxml = sqlMapxml.replace("&updatesql&", updatesql);
        sqlMapxml = sqlMapxml.replace("&deletefromsql&", deletefromsql);
        System.out.println(sqlMapxml);

        return sqlMapxml;
    }

    @Override
    public void deployIdUpdate(Long id, Long deployId) {
        if (id == null) {
            throw new BasicServiceException("id不允许为空");
        }
        LnkInnerObject record = new LnkInnerObject();
        record.setId(id);
        record.setDeployId(deployId);
        lnkInnerObjectMapper.deployIdUpdate(record);
    }
}
